package cn.bdqn.Dbutis;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by SMD on 2018/5/25.
 */
public class c3p0Pool {
    private static ComboPooledDataSource ds = new ComboPooledDataSource();

    public static ComboPooledDataSource getDs() {
        return ds;
    }

    public static void setDs(ComboPooledDataSource ds) {
        c3p0Pool.ds = ds;
    }

    public static Connection getConn() throws SQLException {
        return ds.getConnection();
    }


    public static void closeAll(ResultSet resultSet, PreparedStatement preparedStatement, Connection connection) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
